<?php
include_once 'BaseS.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/application/model/CatM.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/application/model/DogM.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/application/model/MemberTokenM.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Util.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Regex.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/ImgUploads.php';

class AppPetS extends BaseS {
	
	public function __construct() {
		parent::__construct ();
		parent::setTarget ( $this );
	}
	
	public function registCat(){
		
		$result = array("status" => 0, "msg" => "", "catId" => 0, "photoName" => "");
		
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ; 
		
		$name 			= isset($_POST['name']) ? $_POST['name'] : "" ;
		$blood 			= isset($_POST['blood']) ? $_POST['blood'] : 0 ;
		$birthday 		= isset($_POST['birthday']) ? $_POST['birthday'] : "" ;
		$weight 		= isset($_POST['weight']) ? $_POST['weight'] : 0 ;
		
		$dao = new CatM();
		$checkToken = new MemberTokenM();
		$img = new ImgUploads();
		
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
		
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
			
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
		
			if($name == "")		{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($birthday == "")	{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($weight == 0)	{$result["status"] = -6; Util::toEchoJson($result); exit;}
			
			if(Regex::isPunctuation($name, 50))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(!Regex::isNumber($blood, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(Regex::isHtmlTag($birthday, 11))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(!Regex::isFloat($weight, 4))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
			
			$photoPath = $_SERVER ['DOCUMENT_ROOT'].PET_PHOTO_PATH;
			$photoName = $img->ImgUpload($photoPath, $memberId.Util::getNowDate("YmdHis"));
			if(!$photoName){$result["status"] = -12; Util::toEchoJson($result); exit;}
			
			$obj = array(
					"member_id" => $memberId,
					"name" => $name,
					"blood" => $blood,
					"birthday" => $birthday,
					"weight" => $weight,
					"photo" => $photoName,
					"date_create" => Util::getNowDate()
			);
			
			$ret = $dao->insert($obj);
			
			if($ret > 0){
				$result['status'] = 1;
				$result['catId'] = $ret;
				$result['photoName'] = $photoName;
			}else{
				$result['status'] = -3;
			}
			
			Util::toEchoJson($result);
			exit;
			
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
	public function registDog(){
	
		$result = array("status" => 0, "msg" => "", "dogId" => 0, "photoName" => "");
	
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ;
	
		$name 			= isset($_POST['name']) ? $_POST['name'] : "" ;
		$birthday 		= isset($_POST['birthday']) ? $_POST['birthday'] : "" ;
		$weight 		= isset($_POST['weight']) ? $_POST['weight'] : "" ;
		$photo 			= isset($_POST['photo']) ? $_POST['photo'] : "" ;
		$blood_dea10 	= isset($_POST['blood_dea10']) ? $_POST['blood_dea10'] : 0 ;
		$blood_dea11 	= isset($_POST['blood_dea11']) ? $_POST['blood_dea11'] : 0 ;
		$blood_dea12 	= isset($_POST['blood_dea12']) ? $_POST['blood_dea12'] : 0 ;
		$blood_dea3 	= isset($_POST['blood_dea3']) ? $_POST['blood_dea3'] : 0 ;
		$blood_dea4 	= isset($_POST['blood_dea4']) ? $_POST['blood_dea4'] : 0 ;
		$blood_dea5 	= isset($_POST['blood_dea5']) ? $_POST['blood_dea5'] : 0 ;
		$blood_dea6 	= isset($_POST['blood_dea6']) ? $_POST['blood_dea6'] : 0 ;
		$blood_dea7 	= isset($_POST['blood_dea7']) ? $_POST['blood_dea7'] : 0 ;
		$blood_dea8 	= isset($_POST['blood_dea8']) ? $_POST['blood_dea8'] : 0 ;
	
		$dao = new DogM();
		$checkToken = new MemberTokenM();
		$img = new ImgUploads();
	
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
	
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
				
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
	
			if($name == "")			{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($birthday == "")		{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($weight == "")		{$result["status"] = -6; Util::toEchoJson($result); exit;}
				
			if(Regex::isPunctuation($name, 50))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(Regex::isHtmlTag($birthday, 11))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(!Regex::isFloat($weight, 4))			{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(Regex::isHtmlTag($photo, 11))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
			
			$photoPath = $_SERVER ['DOCUMENT_ROOT'].PET_PHOTO_PATH;
			$photoName = $img->ImgUpload($photoPath, $memberId.Util::getNowDate("YmdHis"));
			if(!$photoName){$result["status"] = -12; Util::toEchoJson($result); exit;}
				
			$obj = array(
					"member_id" => $memberId,
					"name" => $name,
					"birthday" => $birthday,
					"weight" => $weight,
					"photo" => $photoName,
					"blood_dea10" => $blood_dea10,
					"blood_dea11" => $blood_dea11,
					"blood_dea12" => $blood_dea12,
					"blood_dea3" => $blood_dea3,
					"blood_dea4" => $blood_dea4,
					"blood_dea5" => $blood_dea5,
					"blood_dea6" => $blood_dea6,
					"blood_dea7" => $blood_dea7,
					"blood_dea8" => $blood_dea8,
					"date_create" => Util::getNowDate()
			);
				
			$ret = $dao->insert($obj);
				
			if($ret >0){
				$result['status'] = 1;
				$result['dogId'] = $ret;
				$result['photoName'] = $photoName;
			}else{
				$result['status'] = -3;
			}
				
			Util::toEchoJson($result);
			exit;
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
	public function searchCatBlood(){

		$result = array("status" => 0, "msg" => "", "bloodList" => array());
		
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ; 
		$searchStart 	= $_POST['searchStart'];
		$searchEnd 		= $_POST['searchEnd'];
		$county			= isset($_POST['county']) ? $_POST['county'] : "";
		$liveZone		= isset($_POST['liveZone']) ? $_POST['liveZone'] : 0;
		$blood 			= isset($_POST['blood']) ? $_POST['blood'] : 0 ;
		
		$dao = new CatM();
		$checkToken = new MemberTokenM();
		
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
		
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
			
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
			
			$ret = $dao->searchBlood($blood, $searchStart, $searchEnd, $county, $liveZone);
			
			if($ret){
				$result['status'] = 1;
				$result['bloodCount'] = $ret['count'];
				$result['bloodList'] = $ret['result'];
			}else{
				$result['status'] = 2;
			}
			
			Util::toEchoJson($result);
			exit;
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
	public function searchDogBlood(){
			$result = array("status" => 0, "msg" => "", "bloodList" => array());
	
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ;
		$searchStart 	= $_POST['searchStart'];
		$searchEnd 		= $_POST['searchEnd'];
		$county			= isset($_POST['county']) ? $_POST['county'] : "";
		$liveZone		= isset($_POST['liveZone']) ? $_POST['liveZone'] : 0;
	
		$bloodArray = array(
				"blood_dea10" => isset($_POST['blood_dea10']) ? $_POST['blood_dea10'] : 0 ,
				"blood_dea11" => isset($_POST['blood_dea11']) ? $_POST['blood_dea11'] : 0 ,
				"blood_dea12" => isset($_POST['blood_dea12']) ? $_POST['blood_dea12'] : 0 ,
				"blood_dea3" => isset($_POST['blood_dea3']) ? $_POST['blood_dea3'] : 0 ,
				"blood_dea4" => isset($_POST['blood_dea4']) ? $_POST['blood_dea4'] : 0 ,
				"blood_dea5" => isset($_POST['blood_dea5']) ? $_POST['blood_dea5'] : 0 ,
				"blood_dea6" => isset($_POST['blood_dea6']) ? $_POST['blood_dea6'] : 0 ,
				"blood_dea7" => isset($_POST['blood_dea7']) ? $_POST['blood_dea7'] : 0 ,
				"blood_dea8" => isset($_POST['blood_dea8']) ? $_POST['blood_dea8'] : 0
		);
	
		$dao = new DogM();
		$checkToken = new MemberTokenM();
	
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
	
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
				
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
				
			$ret = $dao->searchBlood($bloodArray, $searchStart, $searchEnd, $county, $liveZone);
				
			if($ret){
				$result['status'] = 1;
				
				foreach($ret['result'] as $row){
					$row->blood = "";
					$row->blood .= $row->blood_dea10 == 1 ? ",DEA1(-) " : "";
					$row->blood .= $row->blood_dea11 == 1 ? ",DEA1.1 " : "";
					$row->blood .= $row->blood_dea12 == 1 ? ",DEA1.2 " : "";
					$row->blood .= $row->blood_dea3 == 1 ? ",DEA3 " : "";
					$row->blood .= $row->blood_dea4 == 1 ? ",DEA4 " : "";
					$row->blood .= $row->blood_dea5 == 1 ? ",DEA5 " : "";
					$row->blood .= $row->blood_dea6 == 1 ? ",DEA6 " : "";
					$row->blood .= $row->blood_dea7 == 1 ? ",DEA7 " : "";
					$row->blood .= $row->blood_dea8 == 1 ? ",DEA8 " : "";
					$row->blood = substr($row->blood, 1);
					
					unset($row->blood_dea10);
					unset($row->blood_dea11);
					unset($row->blood_dea12);
					unset($row->blood_dea3);
					unset($row->blood_dea4);
					unset($row->blood_dea5);
					unset($row->blood_dea6);
					unset($row->blood_dea7);
					unset($row->blood_dea8);
				}
				
				$result['bloodCount'] = $ret['count'];
				$result['bloodList'] = $ret['result'];
				
			}else{
				$result['status'] = 2;
			}
				
			Util::toEchoJson($result);
			exit;
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
	public function queryMyPetListBoth(){
		
		$result = array("status" => 0, "msg" => "", "catCount" => 0, "dogCount" => 0, "catList" => array(), "dogList" => array());
		
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ;
		$catStart 		= $_POST['catStart'];
		$catEnd 		= $_POST['catEnd'];
		$dogStart 		= $_POST['dogStart'];
		$dogEnd 		= $_POST['dogEnd'];
		
		$dogDao = new DogM();
		$catDao = new CatM();
		$checkToken = new MemberTokenM();
		
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
		
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
		
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
		
			$catList = $catDao->getList($memberId, $catStart, $catEnd);
			$dogList = $dogDao->getList($memberId, $dogStart, $dogEnd);
			
			if($catList['count'] > 0 && $dogList['count'] > 0){
				$result['status'] = 1;
				$result['catCount'] = $catList['count'];
				$result['catList'] = $catList['result'];
				$result['dogCount'] = $dogList['count'];
				
			foreach($dogList['result'] as $row){
					$row->blood = "";
					$row->blood .= $row->blood_dea10 == 1 ? ",DEA1(-) " : "";
					$row->blood .= $row->blood_dea11 == 1 ? ",DEA1.1 " : "";
					$row->blood .= $row->blood_dea12 == 1 ? ",DEA1.2 " : "";
					$row->blood .= $row->blood_dea3 == 1 ? ",DEA3 " : "";
					$row->blood .= $row->blood_dea4 == 1 ? ",DEA4 " : "";
					$row->blood .= $row->blood_dea5 == 1 ? ",DEA5 " : "";
					$row->blood .= $row->blood_dea6 == 1 ? ",DEA6 " : "";
					$row->blood .= $row->blood_dea7 == 1 ? ",DEA7 " : "";
					$row->blood .= $row->blood_dea8 == 1 ? ",DEA8 " : "";
					$row->blood = substr($row->blood, 1);
					
					unset($row->blood_dea10);
					unset($row->blood_dea11);
					unset($row->blood_dea12);
					unset($row->blood_dea3);
					unset($row->blood_dea4);
					unset($row->blood_dea5);
					unset($row->blood_dea6);
					unset($row->blood_dea7);
					unset($row->blood_dea8);
				}
				
				$result['dogList'] = $dogList['result'];
				
			}else if($catList['count'] > 0 && $dogList['count'] <= 0){
				$result['status'] = 2;
				$result['catCount'] = $catList['count'];
				$result['catList'] = $catList['result'];
				
			}else if($catList['count'] <= 0 && $dogList['count'] > 0){
				$result['status'] = 3;
				$result['dogCount'] = $dogList['count'];
				
				foreach($dogList['result'] as $row){
					$row->blood = "";
					$row->blood .= $row->blood_dea10 == 1 ? ",DEA1(-) " : "";
					$row->blood .= $row->blood_dea11 == 1 ? ",DEA1.1 " : "";
					$row->blood .= $row->blood_dea12 == 1 ? ",DEA1.2 " : "";
					$row->blood .= $row->blood_dea3 == 1 ? ",DEA3 " : "";
					$row->blood .= $row->blood_dea4 == 1 ? ",DEA4 " : "";
					$row->blood .= $row->blood_dea5 == 1 ? ",DEA5 " : "";
					$row->blood .= $row->blood_dea6 == 1 ? ",DEA6 " : "";
					$row->blood .= $row->blood_dea7 == 1 ? ",DEA7 " : "";
					$row->blood .= $row->blood_dea8 == 1 ? ",DEA8 " : "";
					$row->blood = substr($row->blood, 1);
					
					unset($row->blood_dea10);
					unset($row->blood_dea11);
					unset($row->blood_dea12);
					unset($row->blood_dea3);
					unset($row->blood_dea4);
					unset($row->blood_dea5);
					unset($row->blood_dea6);
					unset($row->blood_dea7);
					unset($row->blood_dea8);
				}
				
				$result['dogList'] = $dogList['result'];
			}else if($catList['count'] <= 0 && $dogList['count'] <= 0){
				$result['status'] = 4;
			}else{
				$result['status'] = -3;
			}
			
			Util::toEchoJson($result);
			exit;
		}else{
			Util::toEchoJson($result);
			exit;
		}	
	}
	
	public function queryMyPetListCat(){
		
		$result = array("status" => 0, "msg" => "", "catCount" => 0, "catList" => array());
	
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ;
		$catStart 		= $_POST['catStart'];
		$catEnd 		= $_POST['catEnd'];
	
		$catDao = new CatM();
		$checkToken = new MemberTokenM();
	
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
	
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
	
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
	
			$catList = $catDao->getList($memberId, $catStart, $catEnd);
				
			if($catList['count'] > 0 ){
				
				$result['status'] = 2;
				$result['catCount'] = $catList['count'];
				$result['catList'] = $catList['result'];
	
			}else if($catList['count'] <= 0){
				$result['status'] = 4;
			}else{
				$result['status'] = -3;
			}
				
			Util::toEchoJson($result);
			exit;
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
	public function queryMyPetListDog(){
	
		$result = array("status" => 0, "msg" => "", "dogCount" => 0, "dogList" => array());
	
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ;
		$dogStart 		= $_POST['dogStart'];
		$dogEnd 		= $_POST['dogEnd'];
	
		$dogDao = new DogM();
		$checkToken = new MemberTokenM();
	
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
	
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
	
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
	
			$dogList = $dogDao->getList($memberId, $dogStart, $dogEnd);
			
			if($dogList['count'] > 0){
				$result['status'] = 3;
				$result['dogCount'] = $dogList['count'];
	
				foreach($dogList['result'] as $row){
					
					$row->blood = "";
					$row->blood .= $row->blood_dea10 == 1 ? ",DEA1(-) " : "";
					$row->blood .= $row->blood_dea11 == 1 ? ",DEA1.1 " : "";
					$row->blood .= $row->blood_dea12 == 1 ? ",DEA1.2 " : "";
					$row->blood .= $row->blood_dea3 == 1 ? ",DEA3 " : "";
					$row->blood .= $row->blood_dea4 == 1 ? ",DEA4 " : "";
					$row->blood .= $row->blood_dea5 == 1 ? ",DEA5 " : "";
					$row->blood .= $row->blood_dea6 == 1 ? ",DEA6 " : "";
					$row->blood .= $row->blood_dea7 == 1 ? ",DEA7 " : "";
					$row->blood .= $row->blood_dea8 == 1 ? ",DEA8 " : "";
					$row->blood = substr($row->blood, 1);
					
					unset($row->blood_dea10);
					unset($row->blood_dea11);
					unset($row->blood_dea12);
					unset($row->blood_dea3);
					unset($row->blood_dea4);
					unset($row->blood_dea5);
					unset($row->blood_dea6);
					unset($row->blood_dea7);
					unset($row->blood_dea8);
				}
	
				$result['dogList'] = $dogList['result'];
			}else if($dogList['count'] <= 0){
				$result['status'] = 4;
			}else{
				$result['status'] = -3;
			}
				
			Util::toEchoJson($result);
			exit;
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
	public function getBloodDetail(){
		
		$result = array("status" => 0, "msg" => "", "detail" => new stdClass());
		
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ;
		$species		= isset($_POST['species']) ? $_POST['species'] : 0 ;
		$petId			= isset($_POST['petId']) ? $_POST['petId'] : 0 ;
		
		$checkToken = new MemberTokenM();
		
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
		
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
		
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
		
			switch($species){
				case 2 :
					$catDao = new CatM();
					$ret = $catDao->getBloodDetail($petId);
					$result['status'] = 1;
					$result['detail'] = $ret;
					Util::toEchoJson($result);
					exit;
					
				case 1 :
					
					$dogDao = new DogM();
					$ret = $dogDao->getBloodDetail($petId);
					$result['status'] = 1;
					
					$ret->blood = "";
					$ret->blood .= $ret->blood_dea10 == 1 ? ",DEA1(-) " : "";
					$ret->blood .= $ret->blood_dea11 == 1 ? ",DEA1.1 " : "";
					$ret->blood .= $ret->blood_dea12 == 1 ? ",DEA1.2 " : "";
					$ret->blood .= $ret->blood_dea3 == 1 ? ",DEA3 " : "";
					$ret->blood .= $ret->blood_dea4 == 1 ? ",DEA4 " : "";
					$ret->blood .= $ret->blood_dea5 == 1 ? ",DEA5 " : "";
					$ret->blood .= $ret->blood_dea6 == 1 ? ",DEA6 " : "";
					$ret->blood .= $ret->blood_dea7 == 1 ? ",DEA7 " : "";
					$ret->blood .= $ret->blood_dea8 == 1 ? ",DEA8 " : "";
					$ret->blood = substr($ret->blood, 1);
							
					unset($ret->blood_dea10);
					unset($ret->blood_dea11);
					unset($ret->blood_dea12);
					unset($ret->blood_dea3);
					unset($ret->blood_dea4);
					unset($ret->blood_dea5);
					unset($ret->blood_dea6);
					unset($ret->blood_dea7);
					unset($ret->blood_dea8);
					
					$result['detail'] = $ret;
					Util::toEchoJson($result);
					exit;
					
				default:
					
					$result['status'] == -3;
					Util::toEchoJson($result);
					exit;
			}
			
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
	
	public function getMyPetDetail(){
	
		$result = array("status" => 0, "msg" => "", "detail" => new stdClass());
	
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ;
		$species		= isset($_POST['species']) ? $_POST['species'] : 0 ;
		$petId			= isset($_POST['petId']) ? $_POST['petId'] : 0 ;
	
		$checkToken = new MemberTokenM();
	
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
	
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
	
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
	
			switch($species){
				case 2 :
						
					$catDao = new CatM();
					$ret = $catDao->getMyPetDetail($memberId, $petId);
					$result['status'] = 1;
					$result['detail'] = $ret;
					Util::toEchoJson($result);
					exit;
						
				case 1 :
						
					$dogDao = new DogM();
					$ret = $dogDao->getMyPetDetail($memberId, $petId);
					$result['status'] = 1;
						
					if($ret){
						
						$ret->blood = "";
						$ret->blood .= $ret->blood_dea10 == 1 ? ",DEA1(-) " : "";
						$ret->blood .= $ret->blood_dea11 == 1 ? ",DEA1.1 " : "";
						$ret->blood .= $ret->blood_dea12 == 1 ? ",DEA1.2 " : "";
						$ret->blood .= $ret->blood_dea3 == 1 ? ",DEA3 " : "";
						$ret->blood .= $ret->blood_dea4 == 1 ? ",DEA4 " : "";
						$ret->blood .= $ret->blood_dea5 == 1 ? ",DEA5 " : "";
						$ret->blood .= $ret->blood_dea6 == 1 ? ",DEA6 " : "";
						$ret->blood .= $ret->blood_dea7 == 1 ? ",DEA7 " : "";
						$ret->blood .= $ret->blood_dea8 == 1 ? ",DEA8 " : "";
						$ret->blood = substr($ret->blood, 1);
						
						unset($ret->blood_dea10);
						unset($ret->blood_dea11);
						unset($ret->blood_dea12);
						unset($ret->blood_dea3);
						unset($ret->blood_dea4);
						unset($ret->blood_dea5);
						unset($ret->blood_dea6);
						unset($ret->blood_dea7);
						unset($ret->blood_dea8);
						
						$result['detail'] = $ret;
						Util::toEchoJson($result);
						exit;
						
					}else{
						$result['status'] == -3;
						Util::toEchoJson($result);
						exit;
					}
						
				default:
					$result['status'] == -3;
					Util::toEchoJson($result);
					exit;
			}
				
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
	public function deleteMyPet(){
	
		$result = array("status" => 0, "msg" => "");
	
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ;
		$species		= isset($_POST['species']) ? $_POST['species'] : 0 ;
		$petId			= isset($_POST['petId']) ? $_POST['petId'] : 0 ;
	
		$checkToken = new MemberTokenM();
	
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
	
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
	
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
	
			switch($species){
				case 1 :
	
					$catDao = new CatM();
					$ret = $catDao->delete($petId);
					$result['status'] = 1;
					Util::toEchoJson($result);
					exit;
	
				case 2 :
	
					$dogDao = new DogM();
					$ret = $dogDao->delete($petId);
					$result['status'] = 1;
					Util::toEchoJson($result);
					exit;
	
				default:
	
					$result['status'] == -3;
					Util::toEchoJson($result);
					exit;
			}
	
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
	public function updateCat(){
	
		$result = array("status" => 0, "msg" => "", "photoName" => "");
	
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ;
	
		$name 			= isset($_POST['name']) ? $_POST['name'] : "" ;
		$blood 			= isset($_POST['blood']) ? $_POST['blood'] : 0 ;
		$birthday 		= isset($_POST['birthday']) ? $_POST['birthday'] : "" ;
		$weight 		= isset($_POST['weight']) ? $_POST['weight'] : 0 ;
		$petId			= isset($_POST['petId']) ? $_POST['petId'] : 0 ;
	
		$dao = new CatM();
		$checkToken = new MemberTokenM();
		$img = new ImgUploads();
	
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
	
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
				
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
	
			if($name == "")		{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($blood == 0)		{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($birthday == "")	{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($weight == 0)	{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($photo == "")	{$result["status"] = -6; Util::toEchoJson($result); exit;}
				
			if(Regex::isPunctuation($name, 50))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(!Regex::isNumber($blood, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(Regex::isHtmlTag($birthday, 11))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(!Regex::isFloat($weight, 4))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(Regex::isHtmlTag($photo, 11))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
			
			$photoPath = $_SERVER ['DOCUMENT_ROOT'].PET_PHOTO_PATH;
			$photoName = $img->ImgUpload($photoPath, $memberId.Util::getNowDate("YmdHis"));
			if(!$photoName){$result["status"] = -12; Util::toEchoJson($result); exit;}
				
			$obj = array(
					"id" => $petId,
					"member_id" => $memberId,
					"name" => $name,
					"blood" => $blood,
					"birthday" => $birthday,
					"weight" => $weight,
					"photo" => $photoName
			);
				
			$ret = $dao->update($obj);
				
			if($ret){
				$result['status'] = 1;
				$result['photoName'] = $photoName;
			}else{
				$result['status'] = -3;
			}
				
			Util::toEchoJson($result);
			exit;
				
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
	public function updateDog(){
	
		$result = array("status" => 0, "msg" => "", "photoName" => "");
	
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ;
	
		$name 			= isset($_POST['name']) ? $_POST['name'] : "" ;
		$birthday 		= isset($_POST['birthday']) ? $_POST['birthday'] : "" ;
		$weight 		= isset($_POST['weight']) ? $_POST['weight'] : "" ;
		$blood_dea10 	= isset($_POST['blood_dea10']) ? $_POST['blood_dea10'] : 0 ;
		$blood_dea11 	= isset($_POST['blood_dea11']) ? $_POST['blood_dea11'] : 0 ;
		$blood_dea12 	= isset($_POST['blood_dea12']) ? $_POST['blood_dea12'] : 0 ;
		$blood_dea3 	= isset($_POST['blood_dea3']) ? $_POST['blood_dea3'] : 0 ;
		$blood_dea4 	= isset($_POST['blood_dea4']) ? $_POST['blood_dea4'] : 0 ;
		$blood_dea5 	= isset($_POST['blood_dea5']) ? $_POST['blood_dea5'] : 0 ;
		$blood_dea6 	= isset($_POST['blood_dea6']) ? $_POST['blood_dea6'] : 0 ;
		$blood_dea7 	= isset($_POST['blood_dea7']) ? $_POST['blood_dea7'] : 0 ;
		$blood_dea8 	= isset($_POST['blood_dea8']) ? $_POST['blood_dea8'] : 0 ;
		$petId			= isset($_POST['petId']) ? $_POST['petId'] : 0 ;
	
		$dao = new DogM();
		$checkToken = new MemberTokenM();
		$img = new ImgUploads();
	
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
	
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
				
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
	
			if($name == "")			{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($birthday == "")		{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($weight == "")		{$result["status"] = -6; Util::toEchoJson($result); exit;}
			if($photo == "")		{$result["status"] = -6; Util::toEchoJson($result); exit;}
				
			if(Regex::isPunctuation($name, 50))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(Regex::isHtmlTag($birthday, 11))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(!Regex::isFloat($weight, 4))			{$result["status"] = -3; Util::toEchoJson($result); exit;}
			if(Regex::isHtmlTag($photo, 11))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
			
			$photoPath = $_SERVER ['DOCUMENT_ROOT'].PET_PHOTO_PATH;
			$photoName = $img->ImgUpload($photoPath, $memberId.Util::getNowDate("YmdHis"));
			if(!$photoName){$result["status"] = -12; Util::toEchoJson($result); exit;}
				
			$obj = array(
					"id" => $petId,
					"member_id" => $memberId,
					"name" => $name,
					"birthday" => $birthday,
					"weight" => $weight,
					"photo" => $photoName,
					"blood_dea10" => $blood_dea10,
					"blood_dea11" => $blood_dea11,
					"blood_dea12" => $blood_dea12,
					"blood_dea3" => $blood_dea3,
					"blood_dea4" => $blood_dea4,
					"blood_dea5" => $blood_dea5,
					"blood_dea6" => $blood_dea6,
					"blood_dea7" => $blood_dea7,
					"blood_dea8" => $blood_dea8
			);
				
			$ret = $dao->update($obj);
				
			if($ret){
				$result['status'] = 1;
				$result['photoName'] = $photoName;
			}else{
				$result['status'] = -3;
			}
				
			Util::toEchoJson($result);
			exit;
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
}

if(isset($_POST["action"])) {
	$service = new AppPetS ();
	$service->__call ( $_POST["action"], null );
} 
?>